Overview#
This notebook gives a general overview of the features included in the dataset.
Show imports
%load_ext autoreload
%autoreload 2
import os
import dimcat as dc
import pandas as pd
import plotly.express as px
from dimcat import filters, plotting
from IPython.display import display
import utils
RESULTS_PATH = os.path.abspath(os.path.join(utils.OUTPUT_FOLDER, "overview"))
os.makedirs(RESULTS_PATH, exist_ok=True)
def make_output_path(
filename: str,
extension=None,
path=RESULTS_PATH,
) -> str:
return utils.make_output_path(filename=filename, extension=extension, path=path)
def save_figure_as(
fig, filename, formats=("png", "pdf"), directory=RESULTS_PATH, **kwargs
):
if formats is not None:
for fmt in formats:
plotting.write_image(fig, filename, directory, format=fmt, **kwargs)
else:
plotting.write_image(fig, filename, directory, **kwargs)
Loading data
D = utils.get_dataset("couperin_concerts", corpus_release="v2.3")
package = D.inputs.get_package()
package_info = package._package.custom
git_tag = package_info.get("git_tag")
utils.print_heading("Data and software versions")
print("François Couperin – Concerts Royaux version v2.3")
print(f"Datapackage '{package.package_name}' @ {git_tag}")
print(f"dimcat version {dc.__version__}\n")
D
Data and software versions
--------------------------
François Couperin – Concerts Royaux version v2.3
Datapackage 'couperin_concerts' @ v2.3
dimcat version 3.4.0
Dataset
=======
{'inputs': {'basepath': None,
'packages': {'couperin_concerts': ["'couperin_concerts.measures' (MuseScoreFacetName.MuseScoreMeasures)",
"'couperin_concerts.notes' (MuseScoreFacetName.MuseScoreNotes)",
"'couperin_concerts.expanded' (MuseScoreFacetName.MuseScoreHarmonies)",
"'couperin_concerts.chords' (MuseScoreFacetName.MuseScoreChords)",
"'couperin_concerts.metadata' (FeatureName.Metadata)"]}},
'outputs': {'basepath': None, 'packages': {}},
'pipeline': []}
filtered_D = filters.HasHarmonyLabelsFilter(keep_values=[True]).process(D)
all_metadata = filtered_D.get_metadata()
assert len(all_metadata) > 0, "No pieces selected for analysis."
all_metadata
| TimeSig | KeySig | last_mc | last_mn | length_qb | last_mc_unfolded | last_mn_unfolded | length_qb_unfolded | volta_mcs | all_notes_qb | ... | has_drumset | ambitus | path | originalFormat | staff_1_instrument | staff_1_ambitus | staff_2_instrument | staff_2_ambitus | staff_3_instrument | staff_3_ambitus | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| corpus | piece | |||||||||||||||||||||
| couperin_concerts | c01n01_prelude | {1: '4/4'} | {1: 1} | 25 | 23 | 98.0 | 25 | 23 | 98.0 | () | 219.00 | ... | 0 | 36-84 (C2-C6) | MS3/c01n01_prelude.mscx | xml | Instrument 1 | 59-84 (B3-C6) | Instrument 1 | 36-57 (C2-A3) | <NA> | <NA> |
| c01n02_allemande | {1: '4/4'} | {1: 1} | 20 | 18 | 72.0 | 40 | 36 | 144.0 | () | 168.50 | ... | 0 | 31-83 (G1-B5) | MS3/c01n02_allemande.mscx | xml | Instrument 1 | 59-83 (B3-B5) | Instrument 1 | 31-66 (G1-F#4) | <NA> | <NA> | |
| c01n03_sarabande | {1: '3/4'} | {1: -2} | 30 | 28 | 90.0 | 56 | 56 | 168.0 | (8], [9]], [[29], [30) | 237.75 | ... | 0 | 31-81 (G1-A5) | MS3/c01n03_sarabande.mscx | xml | Instrument 1 | 58-81 (Bb3-A5) | Instrument 1 | 31-67 (G1-G4) | <NA> | <NA> | |
| c01n04_gavotte | {1: '2/2'} | {1: -2} | 18 | 14 | 60.0 | 32 | 28 | 112.0 | (5], [6]], [[17], [18) | 135.00 | ... | 0 | 38-79 (D2-G5) | MS3/c01n04_gavotte.mscx | xml | Instrument 1 | 58-79 (Bb3-G5) | Instrument 1 | 38-57 (D2-A3) | <NA> | <NA> | |
| c01n05_gigue | {1: '6/8'} | {1: 1} | 33 | 30 | 93.5 | 62 | 60 | 180.0 | (11], [12]], [[32], [33) | 194.00 | ... | 0 | 38-83 (D2-B5) | MS3/c01n05_gigue.mscx | xml | Instrument 1 | 59-83 (B3-B5) | Instrument 1 | 38-64 (D2-E4) | <NA> | <NA> | |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | |
| parnasse_03 | {1: '4/4'} | {1: 2} | 59 | 58 | 235.0 | 59 | 58 | 235.0 | () | 655.00 | ... | 0 | 38-86 (D2-D6) | MS3/parnasse_03.mscx | <NA> | Piano | 61-86 (C#4-D6) | Piano | 57-84 (A3-C6) | Piano | 38-67 (D2-G4) | |
| parnasse_04 | {1: '3/8'} | {1: 2} | 57 | 57 | 84.5 | 57 | 57 | 84.5 | () | 196.62 | ... | 0 | 40-83 (E2-B5) | MS3/parnasse_04.mscx | <NA> | Piano | 62-83 (D4-B5) | Piano | 57-83 (A3-B5) | Piano | 40-69 (E2-A4) | |
| parnasse_05 | {1: '4/4'} | {1: 2} | 27 | 26 | 107.5 | 27 | 26 | 107.5 | () | 276.00 | ... | 0 | 36-83 (C2-B5) | MS3/parnasse_05.mscx | <NA> | Piano | 59-83 (B3-B5) | Piano | 55-83 (G3-B5) | Piano | 36-66 (C2-F#4) | |
| parnasse_06 | {1: '3/8'} | {1: 2} | 32 | 32 | 48.0 | 32 | 32 | 48.0 | () | 121.63 | ... | 0 | 38-83 (D2-B5) | MS3/parnasse_06.mscx | <NA> | Piano | 65-83 (E#4-B5) | Piano | 64-83 (E4-B5) | Piano | 38-66 (D2-F#4) | |
| parnasse_07 | {1: '4/4'} | {1: 2} | 53 | 53 | 212.0 | 53 | 53 | 212.0 | () | 514.00 | ... | 0 | 38-86 (D2-D6) | MS3/parnasse_07.mscx | <NA> | Piano | 61-84 (C#4-C6) | Piano | 59-86 (B3-D6) | Piano | 38-69 (D2-A4) |
84 rows × 53 columns
mean_composition_years = utils.corpus_mean_composition_years(all_metadata)
chronological_order = mean_composition_years.index.to_list()
corpus_colors = dict(zip(chronological_order, utils.CORPUS_COLOR_SCALE))
corpus_names = {
corp: utils.get_corpus_display_name(corp) for corp in chronological_order
}
chronological_corpus_names = list(corpus_names.values())
corpus_name_colors = {
corpus_names[corp]: color for corp, color in corpus_colors.items()
}
mean_composition_years
corpus
couperin_concerts 1723.380952
Name: mean_composition_year, dtype: float64
Composition dates#
This section relies on the dataset’s metadata.
valid_composed_start = pd.to_numeric(all_metadata.composed_start, errors="coerce")
valid_composed_end = pd.to_numeric(all_metadata.composed_end, errors="coerce")
print(
f"Composition dates range from {int(valid_composed_start.min())} {valid_composed_start.idxmin()} "
f"to {int(valid_composed_end.max())} {valid_composed_end.idxmax()}."
)
Composition dates range from 1722 ('couperin_concerts', 'c01n01_prelude') to 1724 ('couperin_concerts', 'c05n01_prelude').
Mean composition years per corpus#
def make_summary(metadata_df):
piece_is_annotated = metadata_df.label_count > 0
return metadata_df[piece_is_annotated].copy()
Show source
summary = make_summary(all_metadata)
bar_data = pd.concat(
[
mean_composition_years.rename("year"),
summary.groupby(level="corpus").size().rename("pieces"),
],
axis=1,
).reset_index()
N = len(summary)
fig = px.bar(
bar_data,
x="year",
y="pieces",
color="corpus",
color_discrete_map=corpus_colors,
title=f"Temporal coverage of the {N} annotated pieces in the Distant Listening Corpus",
)
fig.update_traces(width=5)
fig.update_layout(**utils.STD_LAYOUT)
fig.update_traces(width=5)
save_figure_as(fig, "pieces_timeline_bars")
fig.show()
summary
| TimeSig | KeySig | last_mc | last_mn | length_qb | last_mc_unfolded | last_mn_unfolded | length_qb_unfolded | volta_mcs | all_notes_qb | ... | has_drumset | ambitus | path | originalFormat | staff_1_instrument | staff_1_ambitus | staff_2_instrument | staff_2_ambitus | staff_3_instrument | staff_3_ambitus | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| corpus | piece | |||||||||||||||||||||
| couperin_concerts | c01n01_prelude | {1: '4/4'} | {1: 1} | 25 | 23 | 98.0 | 25 | 23 | 98.0 | () | 219.00 | ... | 0 | 36-84 (C2-C6) | MS3/c01n01_prelude.mscx | xml | Instrument 1 | 59-84 (B3-C6) | Instrument 1 | 36-57 (C2-A3) | <NA> | <NA> |
| c01n02_allemande | {1: '4/4'} | {1: 1} | 20 | 18 | 72.0 | 40 | 36 | 144.0 | () | 168.50 | ... | 0 | 31-83 (G1-B5) | MS3/c01n02_allemande.mscx | xml | Instrument 1 | 59-83 (B3-B5) | Instrument 1 | 31-66 (G1-F#4) | <NA> | <NA> | |
| c01n03_sarabande | {1: '3/4'} | {1: -2} | 30 | 28 | 90.0 | 56 | 56 | 168.0 | (8], [9]], [[29], [30) | 237.75 | ... | 0 | 31-81 (G1-A5) | MS3/c01n03_sarabande.mscx | xml | Instrument 1 | 58-81 (Bb3-A5) | Instrument 1 | 31-67 (G1-G4) | <NA> | <NA> | |
| c01n04_gavotte | {1: '2/2'} | {1: -2} | 18 | 14 | 60.0 | 32 | 28 | 112.0 | (5], [6]], [[17], [18) | 135.00 | ... | 0 | 38-79 (D2-G5) | MS3/c01n04_gavotte.mscx | xml | Instrument 1 | 58-79 (Bb3-G5) | Instrument 1 | 38-57 (D2-A3) | <NA> | <NA> | |
| c01n05_gigue | {1: '6/8'} | {1: 1} | 33 | 30 | 93.5 | 62 | 60 | 180.0 | (11], [12]], [[32], [33) | 194.00 | ... | 0 | 38-83 (D2-B5) | MS3/c01n05_gigue.mscx | xml | Instrument 1 | 59-83 (B3-B5) | Instrument 1 | 38-64 (D2-E4) | <NA> | <NA> | |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | |
| parnasse_03 | {1: '4/4'} | {1: 2} | 59 | 58 | 235.0 | 59 | 58 | 235.0 | () | 655.00 | ... | 0 | 38-86 (D2-D6) | MS3/parnasse_03.mscx | <NA> | Piano | 61-86 (C#4-D6) | Piano | 57-84 (A3-C6) | Piano | 38-67 (D2-G4) | |
| parnasse_04 | {1: '3/8'} | {1: 2} | 57 | 57 | 84.5 | 57 | 57 | 84.5 | () | 196.62 | ... | 0 | 40-83 (E2-B5) | MS3/parnasse_04.mscx | <NA> | Piano | 62-83 (D4-B5) | Piano | 57-83 (A3-B5) | Piano | 40-69 (E2-A4) | |
| parnasse_05 | {1: '4/4'} | {1: 2} | 27 | 26 | 107.5 | 27 | 26 | 107.5 | () | 276.00 | ... | 0 | 36-83 (C2-B5) | MS3/parnasse_05.mscx | <NA> | Piano | 59-83 (B3-B5) | Piano | 55-83 (G3-B5) | Piano | 36-66 (C2-F#4) | |
| parnasse_06 | {1: '3/8'} | {1: 2} | 32 | 32 | 48.0 | 32 | 32 | 48.0 | () | 121.63 | ... | 0 | 38-83 (D2-B5) | MS3/parnasse_06.mscx | <NA> | Piano | 65-83 (E#4-B5) | Piano | 64-83 (E4-B5) | Piano | 38-66 (D2-F#4) | |
| parnasse_07 | {1: '4/4'} | {1: 2} | 53 | 53 | 212.0 | 53 | 53 | 212.0 | () | 514.00 | ... | 0 | 38-86 (D2-D6) | MS3/parnasse_07.mscx | <NA> | Piano | 61-84 (C#4-C6) | Piano | 59-86 (B3-D6) | Piano | 38-69 (D2-A4) |
84 rows × 53 columns
Composition years histogram#
Show source
hist_data = summary.reset_index()
hist_data.corpus = hist_data.corpus.map(corpus_names)
fig = px.histogram(
hist_data,
x="composed_end",
color="corpus",
labels=dict(
composed_end="decade",
count="pieces",
),
color_discrete_map=corpus_name_colors,
title=f"Temporal coverage of the {N} annotated pieces in the Distant Listening Corpus",
)
fig.update_traces(xbins=dict(size=10))
fig.update_layout(**utils.STD_LAYOUT)
fig.update_legends(font=dict(size=16))
save_figure_as(fig, "pieces_timeline_histogram", height=1250)
fig.show()
Dimensions#
Overview#
def make_overview_table(groupby, group_name="pieces"):
n_groups = groupby.size().rename(group_name)
absolute_numbers = dict(
measures=groupby.last_mn.sum(),
length=groupby.length_qb.sum(),
notes=groupby.n_onsets.sum(),
labels=groupby.label_count.sum(),
)
absolute = pd.DataFrame.from_dict(absolute_numbers)
absolute = pd.concat([n_groups, absolute], axis=1)
sum_row = pd.DataFrame(absolute.sum(), columns=["sum"]).T
absolute = pd.concat([absolute, sum_row])
return absolute
absolute = make_overview_table(summary.groupby("workTitle"))
# print(absolute.astype(int).to_markdown())
absolute.astype(int)
| pieces | measures | length | notes | labels | |
|---|---|---|---|---|---|
| Concert Royal no. 1 | 6 | 137 | 491 | 1859 | 480 |
| Concert Royal no. 2 | 5 | 248 | 711 | 2500 | 597 |
| Concert Royal no. 3 | 8 | 300 | 865 | 3565 | 805 |
| Concert Royal no. 4 | 7 | 242 | 780 | 2743 | 652 |
| Le Parnasse, ou L'Apothéose de Corelli | 7 | 306 | 941 | 4825 | 957 |
| Nouveau Concert, ou Les Goûts-Réunis no. 10 | 4 | 124 | 431 | 1596 | 364 |
| Nouveau Concert, ou Les Goûts-Réunis no. 11 | 8 | 254 | 964 | 2890 | 855 |
| Nouveau Concert, ou Les Goûts-Réunis no. 14 | 4 | 122 | 408 | 1645 | 466 |
| Nouveau Concert, ou Les Goûts-Réunis no. 5 | 5 | 205 | 617 | 2014 | 529 |
| Nouveau Concert, ou Les Goûts-Réunis no. 6 | 5 | 164 | 566 | 2133 | 590 |
| Nouveau Concert, ou Les Goûts-Réunis no. 7 | 6 | 171 | 637 | 2364 | 602 |
| Nouveau Concert, ou Les Goûts-Réunis no. 8 | 11 | 420 | 1620 | 3542 | 939 |
| Nouveau Concert, ou Les Goûts-Réunis no. 9 | 8 | 252 | 800 | 3211 | 919 |
| sum | 84 | 2945 | 9834 | 34887 | 8755 |
def summarize_dataset(D):
all_metadata = D.get_metadata()
summary = make_summary(all_metadata)
return make_overview_table(summary.groupby(level=0))
corpus_summary = summarize_dataset(D)
print(corpus_summary.astype(int).to_markdown())
| | pieces | measures | length | notes | labels |
|:------------------|---------:|-----------:|---------:|--------:|---------:|
| couperin_concerts | 84 | 2945 | 9834 | 34887 | 8755 |
| sum | 84 | 2945 | 9834 | 34887 | 8755 |
Measures#
all_measures = D.get_feature("measures")
print(
f"{len(all_measures.index)} measures over {len(all_measures.groupby(level=[0,1]))} files."
)
all_measures.head()
3394 measures over 91 files.
| mc | mn | quarterbeats | duration_qb | keysig | timesig | act_dur | mc_offset | numbering_offset | dont_count | barline | breaks | repeats | next | volta | markers | jump_bwd | jump_fwd | play_until | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| corpus | piece | i | |||||||||||||||||||
| couperin_concerts | c01n01_prelude | 0 | 1 | 0 | 0 | 2.0 | 1 | 4/4 | 1/2 | 1/2 | <NA> | 1 | <NA> | <NA> | firstMeasure | (2,) | <NA> | <NA> | <NA> | <NA> | <NA> |
| 1 | 2 | 1 | 2 | 4.0 | 1 | 4/4 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (3,) | <NA> | <NA> | <NA> | <NA> | <NA> | ||
| 2 | 3 | 2 | 6 | 4.0 | 1 | 4/4 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (4,) | <NA> | <NA> | <NA> | <NA> | <NA> | ||
| 3 | 4 | 3 | 10 | 4.0 | 1 | 4/4 | 1 | 0 | <NA> | <NA> | <NA> | line | <NA> | (5,) | <NA> | <NA> | <NA> | <NA> | <NA> | ||
| 4 | 5 | 4 | 14 | 4.0 | 1 | 4/4 | 1 | 0 | <NA> | <NA> | <NA> | <NA> | <NA> | (6,) | <NA> | <NA> | <NA> | <NA> | <NA> |
all_measures.get_default_analysis().plot_grouped()
Harmony labels#
All symbols, independent of the local key (the mode of which changes their semantics).
try:
all_annotations = D.get_feature("harmonylabels").df
except Exception:
all_annotations = pd.DataFrame()
n_annotations = len(all_annotations.index)
includes_annotations = n_annotations > 0
if includes_annotations:
display(all_annotations.head())
print(f"Concatenated annotation tables contains {all_annotations.shape[0]} rows.")
no_chord = all_annotations.root.isna()
if no_chord.sum() > 0:
print(
f"{no_chord.sum()} of them are not chords. Their values are:"
f" {all_annotations.label[no_chord].value_counts(dropna=False).to_dict()}"
)
all_chords = all_annotations[~no_chord].copy()
print(
f"Dataset contains {all_chords.shape[0]} tokens and {len(all_chords.chord.unique())} types over "
f"{len(all_chords.groupby(level=[0,1]))} documents."
)
all_annotations["corpus_name"] = all_annotations.index.get_level_values(0).map(
utils.get_corpus_display_name
)
all_chords["corpus_name"] = all_chords.index.get_level_values(0).map(
utils.get_corpus_display_name
)
else:
print("Dataset contains no annotations.")
| mc | mn | quarterbeats | duration_qb | mc_onset | mn_onset | timesig | staff | voice | volta | ... | numeral_or_applied_to_numeral | intervals_over_bass | intervals_over_root | scale_degrees | scale_degrees_and_mode | scale_degrees_major | scale_degrees_minor | globalkey | localkey | chord | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| corpus | piece | i | |||||||||||||||||||||
| couperin_concerts | c01n01_prelude | 0 | 1 | 0 | 0 | 2.00 | 0 | 1/2 | 4/4 | 1 | 1 | <NA> | ... | I | (M3, P5) | (M3, P5) | (1, 3, 5) | (1, 3, 5), major | (1, 3, 5) | (1, #3, 5) | G | I | I |
| 1 | 2 | 1 | 2 | 2.00 | 0 | 0 | 4/4 | 1 | 1 | <NA> | ... | V | (M3, P5) | (M3, P5) | (5, 7, 2) | (5, 7, 2), major | (5, 7, 2) | (5, #7, 2) | G | I | V | ||
| 2 | 2 | 1 | 4 | 0.50 | 1/2 | 1/2 | 4/4 | 1 | 1 | <NA> | ... | I | (m3, m6) | (M3, P5) | (3, 5, 1) | (3, 5, 1), major | (3, 5, 1) | (#3, 5, 1) | G | I | I6 | ||
| 3 | 2 | 1 | 9/2 | 0.50 | 5/8 | 5/8 | 4/4 | 1 | 1 | <NA> | ... | I | (M3, P5) | (M3, P5) | (1, 3, 5) | (1, 3, 5), major | (1, 3, 5) | (1, #3, 5) | G | I | I | ||
| 4 | 2 | 1 | 5 | 0.75 | 3/4 | 3/4 | 4/4 | 1 | 1 | <NA> | ... | V | (P4, P5) | (P4, P5) | (5, 1, 2) | (5, 1, 2), major | (5, 1, 2) | (5, 1, 2) | G | I | V(4) |
5 rows × 51 columns
Concatenated annotation tables contains 8376 rows.
Dataset contains 8376 tokens and 241 types over 84 documents.